<template>
  <div class="table-container">
    <el-table :data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
              stripe
              style="width: 100%">
      <el-table-column prop="date" label="日期"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="address" label="地址"></el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      // 模拟API请求获取数据
      const mockData = []
      for (let i = 1; i <= 100; i++) {
        mockData.push({
          date: `2025-06-${i % 30 + 1}`,
          name: `用户${i}`,
          address: `北京市朝阳区${i}号院`
        })
      }
      this.tableData = mockData
      this.total = mockData.length
    },
    handleSizeChange(newSize) {
      this.pageSize = newSize
    },
    handleCurrentChange(newPage) {
      this.currentPage = newPage
    }
  }
}
</script>

<style scoped>
.table-container {
  padding: 20px;
}
</style>